package com.pwc.GAE.blobstore;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.google.appengine.api.blobstore.BlobInfo;
import com.google.appengine.api.blobstore.BlobKey;
import com.google.appengine.api.blobstore.BlobstoreInputStream;
import com.google.appengine.api.blobstore.BlobstoreService;
import com.google.appengine.api.blobstore.BlobstoreServiceFactory;

public class BlobstoreManager {

	
	private HttpServletRequest req;
	private static BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
	private Map<String, List<BlobInfo>> blobInfos;
	

	public BlobstoreManager(HttpServletRequest req) {
		super();
		this.req = req;		
		blobInfos=blobstoreService.getBlobInfos(req);		
	}
	
	
	
	public BlobInfo getSingleBlobInfo(String parameterKey)
	{
		List<BlobInfo> dataList= getMutiBlobInfos(parameterKey);
		BlobInfo fileinfo=dataList.get(0);
		return fileinfo;
	}
	
	public BlobKey getSingleBlobKey(String parameterKey)
	{
		BlobInfo info=getSingleBlobInfo(parameterKey);
		return info.getBlobKey();
	}
	
	
	public List<BlobInfo> getMutiBlobInfos(String parameterKey)
	{
		Map<String, List<BlobInfo>> blobdata=blobstoreService.getBlobInfos(req);
		List<BlobInfo> dataList= blobdata.get(parameterKey);
		return dataList;
	}
	
	
	public List<BlobKey> getMutiBlobKeys(String parameterKey)
	{
		Map<String, List<BlobKey>> blobdata=blobstoreService.getUploads(req);
		List<BlobKey> dataList= blobdata.get(parameterKey);
		return dataList;
	}
	
	



	public HttpServletRequest getReq() {
		return req;
	}


	public void setReq(HttpServletRequest req) {
		this.req = req;
	}


	public Map<String, List<BlobInfo>> getBlobInfos() {
		return blobInfos;
	}


	public void setBlobInfos(Map<String, List<BlobInfo>> blobInfos) {
		this.blobInfos = blobInfos;
	}
	
}
